<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <input type="hidden" id="uid">
    <table id="roleList" lay-filter="roleList"></table>
    <input type="button" value="重新分配角色" class="layui-btn" id="assignBtn">

    <script type="text/javascript" src="<%=request.getContextPath()%>/static/layui/layui/layui.js"></script>
    <script>
        layui.use(['form','layer','laydate','table','laytpl'],function(){
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : top.layer,
                $ = layui.jquery,
                laydate = layui.laydate,
                laytpl = layui.laytpl,
                table = layui.table;
            var uid=$("#uid").val();
            //用户列表
            var tableIns = table.render({
                elem: '#roleList',
                url : '/selectRolesByUserId/'+uid,
                cellMinWidth : 95,
                page : false,
                id : "roleTable",
                cols : [[
                    {type: "checkbox", fixed:"left", width:50},
                    {field: 'id', title: '角色ID', width:135, align:"center"},
                    {field: 'rolename', title: '角色名', width:135, align:"center"}
                ]]
            });
            //重新分配角色
            $("#assignBtn").click(function () {
                //获取uid
                 var uid=$("#uid").val();
                //获取到选中的rid集合
                var checkStatus=table.checkStatus('roleTable');
                var roleArray=checkStatus.data;
                var rids=new Array();
                for(var i=0;i<roleArray.length;i++){
                    rids.push(roleArray[i].id);
                }
                $.ajax({
                    url:'/assignRole',
                    type:'GET',
                    data:{uid:uid,rids:rids},
                    success:function (res) {
                      if(res.code==1004){
                          layui.layer.msg(res.msg);
                          var index1=parent.layer.getFrameIndex(window.name)
                          setTimeout(function () {
                              parent.layer.close(index1);
                          },1000)
                      }
                    }
                });

            });
        });
    </script>
</body>
</html>